

#import "AppController.h"
#import "BLAuthentication.h"

@implementation AppController

- (NSWorkspace *)workspace;
{   
    return [NSWorkspace sharedWorkspace];
}

- (NSArray *)sortDescriptors;
{ 
    return [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"localizedName" ascending:YES]];
}

- (void) awakeFromNib
{
    self.path = @"def";
}

- (void)updateModel
{
    NSRunningApplication *selectedApp = [self.arrayController.selectedObjects objectAtIndex:0];
    NSString *path=[[[selectedApp bundleURL] absoluteString] substringFromIndex:16];

    path = [path substringToIndex:[path length]-1];
    
    BLAuthentication *BLAuth = [BLAuthentication shared];//создание инструмента авторизации
    NSString *p=[[NSBundle mainBundle]resourcePath];
    
    NSString * str = [p stringByAppendingString:@"/ProxyFireWall"];
    NSArray * args3;
    NSString *p2=[@"" stringByAppendingString:str ];
    args3 = [NSArray arrayWithObjects:path,@"s", nil];
    [BLAuth executeCommand:p2 withArgs:args3];
    
    [selectedApp terminate];
    
    self.path = path;

}

- (IBAction)quitAction:(id)sender;
{
	NSRunningApplication *selectedApp = [self.arrayController.selectedObjects objectAtIndex:0];
  
	[selectedApp terminate];
}



@end


// this value transformer simply converts "NSBundleExecutableArchitecture" to a readable string
//
@implementation ExecutableArchitectureTransformer

+ (Class)transformedValueClass;
{
	return [NSString class];
}

+ (BOOL)allowsReverseTransformation;
{
	return NO;
}

- (id)transformedValue:(id)value;
{
	NSString *archStr;
	
	switch ([value intValue])
	{
		case NSBundleExecutableArchitectureI386:
			archStr = @"Intel 32-bit";
			break;
            
		case NSBundleExecutableArchitectureX86_64:
			archStr = @"Intel 64-bit";
			break;
            
		case NSBundleExecutableArchitecturePPC:
			// in case of Rosetta, allow for PPC
			archStr = @"PPC Translated";
			break;
			
		default:
			archStr = @"unknown";
			break;
	}
	return archStr;
}

@end
